package com.liy.framework.common.utils;

import java.lang.reflect.Field;

public class ReflectUtil {
    public ReflectUtil() {
    }

    public static Object getFieldValue(String fieldName, Object obj) {
        return getFieldValue(fieldName, obj, (Object)null);
    }

    public static Object getFieldValue(String fieldName, Object obj, Object defaultValue) {
        try {
            Field field = getField(fieldName, obj.getClass());
            if (field != null) {
                Object value;
                if (!field.isAccessible()) {
                    field.setAccessible(true);
                    value = field.get(obj);
                    field.setAccessible(false);
                } else {
                    value = field.get(obj);
                }

                return value;
            }
        } catch (Exception var5) {
            var5.printStackTrace();
        }

        return defaultValue;
    }

    public static Field getField(String fieldName, Class<?> clazz) {
        Field field;
        for(field = null; clazz != Object.class; clazz = clazz.getSuperclass()) {
            try {
                field = clazz.getDeclaredField(fieldName);
                if (field != null) {
                    break;
                }
            } catch (Exception var4) {
                ;
            }
        }

        return field;
    }
}
